import { buildStorage } from "./StorageHelpers";
import { Contract } from "./index";
import { XrpSafeContractAddress } from "./SafeContract";
import { BridgeDoorNative__factory } from "@peersyst/xrp-evm-contracts";
import { xrplAccountToEvmAddress } from "../../../bridge/util/address-derivation";

export const BridgeDoorContractAddress = xrplAccountToEvmAddress("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");

export const BridgeDoorContract = (xrplBridgeAddress: string, minCreateAmount: number, minRewardAmount: number): Contract => ({
    address: BridgeDoorContractAddress,
    bytecode: BridgeDoorNative__factory.bytecode,
    memory: [
        // (mapping(uint256 => ClaimData) claims) slot: 0 - value: uninitialized
        // (mapping(address => CreateAccountData) createAccounts) slot: 1 - value: uninitialized
        ...buildStorage({
            slot: 2, // GnosisSafeL2 _safe
            value: XrpSafeContractAddress,
        }),
        // (address _tokenAddress) slot: 3 - value: address(0)
        ...buildStorage({
            slot: 4, // address _lockingChainDoor
            value: xrplAccountToEvmAddress(xrplBridgeAddress),
        }),
        // (address _lockingChainIssuer) slot: 5 - value: address(0)
        ...buildStorage({
            slot: 6, // address _lockingChainIssue
            value: "5852500000000000000000000000000000000000000000000000000000000006", // string("XRP")
        }),
        ...buildStorage({
            slot: 7, // address _issuingChainDoor
            value: BridgeDoorContractAddress,
        }),
        // (address _issuingChainIssuer) slot: 8 - value: address(0)
        ...buildStorage({
            slot: 9, // address _issuingChainIssue
            value: "5852500000000000000000000000000000000000000000000000000000000006", // string("XRP")
        }),
        // (bool _isLocking) slot: 10 - value: false
        ...buildStorage({
            slot: 11, // uint256 _signatureReward
            value: minRewardAmount,
        }),
        ...buildStorage({
            slot: 12, // uint256 _minAccountCreateAmount
            value: minCreateAmount,
        }),
    ],
});
